package cn.jly.spring.annotation.ioc;

import cn.jly.spring.annotation.ioc.bean.SpringComponent;
import cn.jly.spring.annotation.ioc.config.MainConfigAware;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author lanyangji
 * @description 测试获取spring组件
 * @date 2020/11/13 下午 5:16
 */
public class IocTestAware {
    AnnotationConfigApplicationContext applicationContext;

    @Before
    public void setUp() throws Exception {
        this.applicationContext = new AnnotationConfigApplicationContext(MainConfigAware.class);
    }

    @After
    public void tearDown() throws Exception {
        applicationContext.close();
    }

    @Test
    public void test() {
        final SpringComponent bean = applicationContext.getBean(SpringComponent.class);
        System.out.println("bean = " + bean);
    }
}
